package com.cn.pack.config;

import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;
import com.netflix.zuul.exception.ZuulException;
import org.apache.commons.lang.StringUtils;

public class PostFilter extends ZuulFilter {
    @Override
    public String filterType() {
        return "post";
    }

    @Override
    public int filterOrder() {
        return 0;
    }

    @Override
    public boolean shouldFilter() {
        return true;
    }

    @Override
    public Object run() throws ZuulException {
        System.out.println("**************** 这是自定义PostFilter");
        RequestContext context = RequestContext.getCurrentContext();
        context.getResponse().setCharacterEncoding("utf-8");
        context.getResponse().setContentType("application/json");
        String responseBody = context.getResponseBody();
        if (StringUtils.isNotEmpty(responseBody)) {
            context.setResponseStatusCode(500);
            context.setResponseBody(responseBody);
        }

        return null;
    }
}
